package com.mall.web.controller.product;

import com.mall.common.annotation.Log;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.core.page.TableDataInfo;
import com.mall.common.enums.BusinessType;
import com.mall.common.utils.poi.ExcelUtil;
import com.mall.product.domain.biz.ProSkuCustomRecordValueBiz;
import com.mall.product.domain.entity.ProSkuCustomRecordValue;
import com.mall.product.service.ProSkuCustomRecordValueService;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * SKU属性值对照Controller
 *
 * @author zhonglin
 * @date 2020-05-07
 */
@Controller
@RequestMapping("/product/skuCustomRecordValue")
public class ProSkuCustomRecordValueController
    extends BaseController {

  private String prefix = "product/skuCustomRecordValue";

  @Autowired
  private ProSkuCustomRecordValueService proSkuCustomRecordValueService;

  @RequiresPermissions("product:skuCustomRecordValue:view")
  @GetMapping()
  public String skuCustomRecordValue() {

    return prefix + "/skuCustomRecordValue";
  }

  /**
   * 查询SKU属性值对照列表
   */
  @RequiresPermissions("product:skuCustomRecordValue:list")
  @PostMapping("/list")
  @ResponseBody
  public TableDataInfo list(ProSkuCustomRecordValue proSkuCustomRecordValue) {

    startPage();
    List<ProSkuCustomRecordValueBiz> list = proSkuCustomRecordValueService.selectProSkuCustomRecordValueList(proSkuCustomRecordValue);
    return getDataTable(list);
  }

  /**
   * 导出SKU属性值对照列表
   */
  @RequiresPermissions("product:skuCustomRecordValue:export")
  @Log(title = "SKU属性值对照", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  @ResponseBody
  public AjaxResult export(ProSkuCustomRecordValue proSkuCustomRecordValue) {

    List<ProSkuCustomRecordValueBiz>      list = proSkuCustomRecordValueService.selectProSkuCustomRecordValueList(proSkuCustomRecordValue);
    ExcelUtil<ProSkuCustomRecordValueBiz> util = new ExcelUtil<ProSkuCustomRecordValueBiz>(ProSkuCustomRecordValueBiz.class);
    return util.exportExcel(list, "skuCustomRecordValue");
  }

  /**
   * 新增SKU属性值对照
   */
  @GetMapping("/add")
  public String add() {

    return prefix + "/add";
  }

  /**
   * 新增保存SKU属性值对照
   */
  @RequiresPermissions("product:skuCustomRecordValue:add")
  @Log(title = "SKU属性值对照", businessType = BusinessType.INSERT)
  @PostMapping("/add")
  @ResponseBody
  public AjaxResult addSave(ProSkuCustomRecordValue proSkuCustomRecordValue) {

    return toAjax(proSkuCustomRecordValueService.insertProSkuCustomRecordValue(proSkuCustomRecordValue));
  }

  /**
   * 修改SKU属性值对照
   */
  @GetMapping("/edit/{skuCustomRecordValueId}")
  public String edit(@PathVariable("skuCustomRecordValueId") Long skuCustomRecordValueId,
                     ModelMap mmap) {

    ProSkuCustomRecordValue proSkuCustomRecordValue = proSkuCustomRecordValueService.selectProSkuCustomRecordValueById(
        skuCustomRecordValueId);
    mmap.put("proSkuCustomRecordValue", proSkuCustomRecordValue);
    return prefix + "/edit";
  }

  /**
   * 修改保存SKU属性值对照
   */
  @RequiresPermissions("product:skuCustomRecordValue:edit")
  @Log(title = "SKU属性值对照", businessType = BusinessType.UPDATE)
  @PostMapping("/edit")
  @ResponseBody
  public AjaxResult editSave(ProSkuCustomRecordValue proSkuCustomRecordValue) {

    return toAjax(proSkuCustomRecordValueService.updateProSkuCustomRecordValue(proSkuCustomRecordValue));
  }

  /**
   * 删除SKU属性值对照
   */
  @RequiresPermissions("product:skuCustomRecordValue:remove")
  @Log(title = "SKU属性值对照", businessType = BusinessType.DELETE)
  @PostMapping("/remove")
  @ResponseBody
  public AjaxResult remove(String ids) {

    return toAjax(proSkuCustomRecordValueService.deleteProSkuCustomRecordValueByIds(ids));
  }

}
